using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library.Utilities;
using NCS.Module.Multimedia.Library.Gallery;
using NCS.Module.Multimedia.Library.Providers;
using NCS.Library;
using NCS.Library.Components;
//using NCS.Module.Adsvertising.Lib;

namespace NCS.Module.Multimedia.Library.Video
{
    public class Video_AlbumController
    {
        public static DataTable GetAlbum()
        {
            return DataAccessProvider.instance().GetAlbumVideo();
        }

        public static string GetAlbumName(int albumid)
        {
            return DataAccessProvider.instance().GetAlbumVideoName(albumid);
        }

        public static DataTable GetAllVideoByKey(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            return DataAccessProvider.instance().GetAllVideoByKey(txtSearch, fromdate, todate, userid);
        }
        
        public static DataTable GetAlbumByNum(int num)
        {
            return DataAccessProvider.instance().GetAlbumVideoByNum(num);
        }
        public static DataTable GetAllAlbum()
        {
            string keycache = AppEnv.PortalId();
            string param = "Video_AlbumController_GetAllAlbum";
            DataCaching data = new DataCaching();
            DataTable dtContents = (DataTable)data.GetHashCache(keycache, param);
            if (dtContents != null) return dtContents;

            dtContents = DataAccessProvider.instance().GetAllAlbumVideo();
            //data.SetHashCache(keycache, param, Constants.CacheExpire, dtContents);
            return dtContents;

            //return DataAccessProvider.instance().GetAllAlbum();
        }
        public static DataTable GetAllAlbum(int start, int end, int total)
        {
            string param = AppEnv.PortalId() + "_" + start + "_" + end + "_" + total;
            string keycache = "Video_AlbumController_GetAllAlbum";
            DataCaching data = new DataCaching();
            DataTable dtContents = (DataTable)data.GetHashCache(keycache, param);
            if (dtContents != null) return dtContents;

            dtContents = DataAccessProvider.instance().GetAllAlbumVideo(start, end, total);
            //data.SetHashCache(keycache, param, Constants.CacheExpire, dtContents);
            return dtContents;

            //return DataAccessProvider.instance().GetAllAlbum(start, end, total);
        }
        public static DataTable GetAllAlbumbyOther(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            return DataAccessProvider.instance().GetAllAlbumVideobyOther(txtSearch, fromdate, todate, userid);
        }

        public static DataTable GetAllAlbumbyOther()
        {
            return DataAccessProvider.instance().GetAllAlbumVideobyOther();
        }

        
        public static void SetAlbumIndex(int id, int index)
        {
            DataAccessProvider.instance().SetAlbumVideoIndex(id, index);
        }

        public static void SetAlbumRank(int id, int rank)
        {
            DataAccessProvider.instance().SetAlbumVideoRank(id, rank);
        }

        public static DataTable GetAllAlbumByParentID(int parentid)
        {
           return DataAccessProvider.instance().GetAllAlbumVideoByParentID(parentid);
        }

        public static DataTable GetAllAlbumByParentID(int _album_parentID, int portalid, int pagesize, int currpage, out int totalRecord)
        {
            return DataAccessProvider.instance().GetAllAlbumVideoByParentID(_album_parentID, portalid, pagesize, currpage, out totalRecord);
        }
        
        public static void SetAlbumStatus(int id, bool status)
        {
            DataAccessProvider.instance().SetAlbumVideoStatus(id, status);
        }

        public static void DeleteAlbum(int _album_ID)
        {
            DataAccessProvider.instance().DeleteAlbumVideo(_album_ID);
        }

        public static int InsertAlbum(Video_AlbumInfo _albumInfo)
        {
            return DataAccessProvider.instance().InsertAlbumVideo(_albumInfo);
        }

        public static void UpdateAlbum(Video_AlbumInfo _albumInfo)
        {
            DataAccessProvider.instance().UpdateAlbumVideo(_albumInfo);
        }

        public static Video_AlbumInfo GetAlbum(int _album_ID)
        {
            return DataAccessProvider.instance().GetAlbumVideo(_album_ID);
        }
        
        public static Video_AlbumInfo GetAlbumByOtherID(int otherid)
        {
            return DataAccessProvider.instance().GetAlbumVideoByOtherID(otherid);
        }
        public static DataRow[] GetAlbumByParentID(DataTable dtRole, int parentID)
        {
            DataRow[] retVal = null;
            retVal = dtRole.Select("AlbumParentID = " + parentID);
            return retVal;
        }
        public static DataTable GetAlbumByParentID(DataTable dtAlbum, DataTable dtReturnAlbum)
        {
            DataRow[] dtItems = GetAlbumByParentID(dtAlbum, 0);
            foreach (DataRow row in dtItems)
            {
                DataRow rowItem = dtReturnAlbum.NewRow();

                rowItem["AlbumID"] = row["AlbumID"].ToString();
                rowItem["AlbumParentID"] = row["AlbumParentID"];
                rowItem["AlbumAvatar"] = row["AlbumAvatar"];
                rowItem["AlbumName"] = row["AlbumName"].ToString();
                rowItem["AlbumDetail"] = row["AlbumDetail"];
                rowItem["Visible"] = row["Visible"];
                rowItem["Visible"] = row["Visible"];
                rowItem["Rank"] = row["Rank"];
                rowItem["Level"] = "0";

                dtReturnAlbum.Rows.Add(rowItem);
                LoadAlbumForCur(dtAlbum, rowItem, dtReturnAlbum);
            }
            return dtReturnAlbum;
        }
        public static DataTable LoadAlbumForCur(DataTable dtAlbum, DataRow curItem, DataTable dtReturnAlbum)
        {
            int level = Convert.ToInt32(curItem["Level"]);
            level += 1;
            int _AlbumID = Convert.ToInt32(curItem["AlbumID"]);
            DataRow[] dtChild = GetAlbumByParentID(dtAlbum, _AlbumID);
            foreach (DataRow row in dtChild)
            {
                DataRow childItem = dtReturnAlbum.NewRow();

                childItem["AlbumID"] = row["AlbumID"].ToString();
                childItem["AlbumParentID"] = row["AlbumParentID"];
                childItem["AlbumAvatar"] = row["AlbumAvatar"];
                childItem["AlbumName"] = MiscUtility.StringIndent(level) + row["AlbumName"].ToString();
                childItem["AlbumDetail"] = row["AlbumDetail"];
                childItem["Visible"] = row["Visible"];
                childItem["Rank"] = row["Rank"];
                childItem["Indexs"] = row["Indexs"];
                childItem["Level"] = level;
                dtReturnAlbum.Rows.Add(childItem);
                LoadAlbumForCur(dtAlbum, childItem, dtReturnAlbum);
            }
            return dtReturnAlbum;
        }
	    
    }

}
